package com.thinkcube.edutainment.adapters;

import java.util.List;

import org.androidannotations.annotations.EBean;
import org.androidannotations.annotations.RootContext;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.thinkcube.edutainment.domain.data.CourseWorkData;
import com.thinkcube.edutainment.service.viewitem.CourseWorkItem;
import com.thinkcube.edutainment.service.viewitem.CourseWorkItem_;

@EBean
public class CourseWorkAdapter extends BaseAdapter {

	List<CourseWorkData> courseWorkData;

	@RootContext
	Context context;

	@Override
	public View getView(final int position, final View convertView,
			final ViewGroup parent) {

		CourseWorkItem courseWorkItem;
		if (convertView == null) {
			courseWorkItem = CourseWorkItem_.build(context);
		} else {
			courseWorkItem = (CourseWorkItem) convertView;
		}

		courseWorkItem.bind(getItem(position));

		return courseWorkItem;
	}

	public List<CourseWorkData> getCourseWorkData() {
		return courseWorkData;
	}

	public void setCourseWorkData(List<CourseWorkData> courseWorkData) {
		this.courseWorkData = courseWorkData;
	}

	@Override
	public int getCount() {
		return courseWorkData.size();
	}

	@Override
	public CourseWorkData getItem(final int position) {
		return courseWorkData.get(position);
	}

	@Override
	public long getItemId(final int position) {
		return position;
	}

}
